import requests

from common.get_login_token import login_token


class IhrmEmp(object):
    @classmethod
    # 添加员工
    def add_emp(cls,token,json_data):
        url = "http://ihrm-test.itheima.net/api/sys/user"
        headers = {"Authorization": token}
        resp = requests.post(url=url, headers=headers, json=json_data)
        return  resp

    @classmethod
    # 修改员工
    def update_emp(cls,emp_id,token,json_data):
        url = "http://ihrm-test.itheima.net/api/sys/user/"+emp_id
        headers = {"Authorization": token}
        resp = requests.put(url=url, headers=headers, json=json_data)
        return resp
    @classmethod
    # 删除员工
    def delete_emp(cls,emp_id,token):
        url = "http://ihrm-test.itheima.net/api/sys/user/"+emp_id
        headers = {"Authorization": token}
        resp = requests.delete(url=url, headers=headers)
        return resp
    @classmethod
    # 查询员工
    def get_emp(cls,emp_id,token):
        url = "http://ihrm-test.itheima.net/api/sys/user/"+emp_id
        headers = {"Authorization": token}
        resp = requests.get(url=url, headers=headers)
        return resp



if __name__ == '__main__':
    json_data = {"username":"张山","mobile":"13494889988","workNumber":"123456789012"}
    token = login_token()
    print('新增员工',IhrmEmp.add_emp(token, json_data).json())
    # json_data2 = {"username":"tom"}
    # id='1524662394020757504'
    # print('修改员工',IhrmEmp.update_emp(id,token,json_data2).json())
    #
    # print('删除员工',IhrmEmp.delete_emp(id,token).json())
    #
    # print('查询员工',IhrmEmp.get_emp(id,token).json())






